package com.ruoyi.peach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.peach.domain.Messages;
import com.ruoyi.peach.service.IMessagesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会话记录Controller
 * 
 * @author ruoyi
 * @date 2025-04-24
 */
@RestController
@RequestMapping("/peach/messages")
public class MessagesController extends BaseController
{
    @Autowired
    private IMessagesService messagesService;

    /**
     * 查询会话记录列表
     */
    @PreAuthorize("@ss.hasPermi('peach:messages:list')")
    @GetMapping("/list")
    public TableDataInfo list(Messages messages)
    {
        startPage();
        List<Messages> list = messagesService.selectMessagesList(messages);
        return getDataTable(list);
    }
    /**
     * 查询所有会话记录列表
     */
    @PreAuthorize("@ss.hasPermi('peach:messages:list')")
    @GetMapping("/listAll")
    public R listAll(Messages messages)
    {
        List<Messages> list = messagesService.selectMessagesList(messages);
        return R.ok(list);
    }

    /**
     * 导出会话记录列表
     */
    @PreAuthorize("@ss.hasPermi('peach:messages:export')")
    @Log(title = "会话记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Messages messages)
    {
        List<Messages> list = messagesService.selectMessagesList(messages);
        ExcelUtil<Messages> util = new ExcelUtil<Messages>(Messages.class);
        util.exportExcel(response, list, "会话记录数据");
    }

    /**
     * 获取会话记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('peach:messages:query')")
    @GetMapping(value = "/{messageId}")
    public AjaxResult getInfo(@PathVariable("messageId") Long messageId)
    {
        return success(messagesService.selectMessagesByMessageId(messageId));
    }

    /**
     * 新增会话记录
     */
    @PreAuthorize("@ss.hasPermi('peach:messages:add')")
    @Log(title = "会话记录", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody Messages messages)
    {
        Messages messages1 = messagesService.insertMessages(messages);
        if(messages1 == null)
        {
            return R.fail("新增会话记录失败");
        }
        else
        {
            return R.ok(messages1);
        }


    }

    /**
     * 修改会话记录
     */
    @PreAuthorize("@ss.hasPermi('peach:messages:edit')")
    @Log(title = "会话记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Messages messages)
    {
        return toAjax(messagesService.updateMessages(messages));
    }
    /**
     * 修改会话记录
     */
    @PreAuthorize("@ss.hasPermi('peach:messages:edit')")
    @Log(title = "会话记录", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    public AjaxResult update(@RequestBody Messages messages)
    {
        return toAjax(messagesService.updateMessages(messages));
    }

    /**
     * 删除会话记录
     */
    @PreAuthorize("@ss.hasPermi('peach:messages:remove')")
    @Log(title = "会话记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{messageIds}")
    public AjaxResult remove(@PathVariable Long[] messageIds)
    {
        return toAjax(messagesService.deleteMessagesByMessageIds(messageIds));
    }
}
